/*
 * TheGame.h
 *
 *  Created on: 14 déc. 2011
 *      Author: M. Alexandre (malexand314@gmail.com)
 */

#ifndef THEGAME_H_
#define THEGAME_H_

#include <vector>
#include <string>
#include <iostream>
#include <sstream>

#include "../Framework/Timer.h"
#include "../Framework/DesignPatterns/Observer.h"
#include "../Framework/Pool.h"
#include "Solver.h"

struct T_GameSet
{
        int aiTab[6];
        int iResult;
};

class T_GameState
{
    public:
        int iTimeRemaining;
        bool bIsGameFinished;
        bool bIsGameWon;
};

/*
 *
 */
class TheGame : public Framework::Observer
{
    public:
        TheGame();
        virtual ~TheGame();

    public:
        void update(Framework::ObserverSubject* _ptSubject);

        bool addOperation(const T_Operation& _operation);
        bool delOperation(const T_Operation& _operation);
        T_GameSet generateAndGetNumbers();
        bool isGameFinished() const { return m_bIsGameFinished; }
        bool isGameWon() const { return m_bIsGameWon; }
        T_GameState localPoolPop();
        bool isPoolDataAvailable();

    private:
        void initIntegerAvailable();
        void generateNumbers();
        void findFirstPossibleSolution();
        void findAllSolution();
        void localPoolPush(int _iTimeRemaining);

    private:
        bool m_bIsGameFinished;
        bool m_bIsGameWon;
        T_GameSet m_gameSet;
        std::vector<int> m_vecIntegerAvailable; // Pioche contenant tous les entiers disponibles pour choisir les 6 nécessaires au jeu
        std::vector<int> m_vecCurrentlyAvailable; // Vecteur des entiers encore en jeu après chaque opération
        std::vector<T_Solution> m_vecSoltions;

        Framework::Timer m_timer;
        Framework::Pool<T_GameState> m_pool;
};

#endif /* THEGAME_H_ */
